package com.wanshi.swagger;

import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @Created by IntelliJ IDEA.
 * @Author Journey
 * @Date 2021/12/9 9:12
 */
@EnableOpenApi
@Configuration
public class Swagger3Config {
    @Bean
    public Docket createRestApi() {
        /* 自定义返回，公共用
        List<Response> responseMessageList = new ArrayList<>();
        Response response500 = new ResponseBuilder().code("500").description("500").build();
        responseMessageList.add(response500);
        */

        /* 自定义公用的参数
        List<RequestParameter> globalRequest = new ArrayList<>();
        globalRequest.add(new RequestParameterBuilder().name("sign").required(true).description("签名").in(ParameterType.QUERY).build());
        */
        return new Docket(DocumentationType.OAS_30)
                .useDefaultResponseMessages(false)
                //.globalResponses(HttpMethod.GET, responseMessageList)
                //.globalRequestParameters(globalRequest)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("yihaomen")
                .description("yihaomen framework......")
                .contact(new Contact("yihaomen。", "http://www.yihaomen.com", ""))
                .version("1.0")
                .build();
    }
}
